package sort.impl;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class ShellSorter extends HSorter {
    private List<Integer> h;

    public ShellSorter(List<Integer> h) {
        super(SorterType.SHELL);
        this.h=h;
    }

    public ShellSorter() {
        super(SorterType.SHELL);
        h = new ArrayList<Integer>();
        h.add(9);
        h.add(6);
        h.add(2);

    }

    public void setHList(List<Integer> h) {
        this.h = h;
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        sort(tComparator, ts, h);
    }

    private <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts, List<Integer> hs) {
        for (Integer aH : hs) {
            setH(aH);
            hSort(tComparator, ts);
        }
        if (hs.get(hs.size() - 1) != 1) {
            setH(1);
            hSort(tComparator, ts);
        }
    }
}
